package org.flashcards;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 *
 * @author siarhei
 */
public class FlashCardsActivity extends Activity {

    private FlashCardsActivity thisActivity;

    private Uri dictionaryUri;

    private TextView wordNumber;

    private TextView expiredNumber;

    private TextView batch0;

    private TextView batch1;

    private TextView batch2;

    private TextView batch3;

    private TextView batch4;

    private TextView batch5;

    private TextView batch6;

    private TextView batch7;

    public FlashCardsActivity() {
        thisActivity = this;
    }

    @Override
    public void onCreate(Bundle icicle) {
        Log.d(getClass().getSimpleName(), "onCreate()");
        super.onCreate(icicle);
        setContentView(R.layout.quiz_main);

        wordNumber = (TextView) findViewById(R.id.word_number_field);
        expiredNumber = (TextView) findViewById(R.id.expired_words);
        batch0 = (TextView) findViewById(R.id.batch0);
        batch1 = (TextView) findViewById(R.id.batch1);
        batch2 = (TextView) findViewById(R.id.batch2);
        batch3 = (TextView) findViewById(R.id.batch3);
        batch4 = (TextView) findViewById(R.id.batch4);
        batch5 = (TextView) findViewById(R.id.batch5);
        batch6 = (TextView) findViewById(R.id.batch6);
        batch7 = (TextView) findViewById(R.id.batch7);
        
        dictionaryUri = Uri.parse("content://org.dictionary.DictionaryProvider/quiz_stats");
        updateStatistics();

        Button startQuiz = (Button) findViewById(R.id.start_quiz2);
        startQuiz.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent i = new Intent(thisActivity, QuizActivity.class);
                startActivity(i);
            }

        });

    }

    private void updateStatistics() {
        Cursor dictCur = getContentResolver().query(dictionaryUri, null, null, null, null);
        dictCur.moveToFirst();

        wordNumber.setText(((Integer)dictCur.getInt(dictCur.getColumnIndex(Statistics.DICTIONARY_SIZE))).toString());
        expiredNumber.setText(((Integer)dictCur.getInt(dictCur.getColumnIndex(Statistics.EXPIRED_SIZE))).toString());
        batch0.setText(((Integer)dictCur.getInt(dictCur.getColumnIndex(Statistics.BATCH0))).toString());
        batch1.setText(((Integer)dictCur.getInt(dictCur.getColumnIndex(Statistics.BATCH1))).toString());
        batch2.setText(((Integer)dictCur.getInt(dictCur.getColumnIndex(Statistics.BATCH2))).toString());
        batch3.setText(((Integer)dictCur.getInt(dictCur.getColumnIndex(Statistics.BATCH3))).toString());
        batch4.setText(((Integer)dictCur.getInt(dictCur.getColumnIndex(Statistics.BATCH4))).toString());
        batch5.setText(((Integer)dictCur.getInt(dictCur.getColumnIndex(Statistics.BATCH5))).toString());
        batch6.setText(((Integer)dictCur.getInt(dictCur.getColumnIndex(Statistics.BATCH6))).toString());
        batch7.setText(((Integer)dictCur.getInt(dictCur.getColumnIndex(Statistics.BATCH7))).toString());
    }

    protected void onResume() {
        super.onResume();
        updateStatistics();
    }
}